
#include <cmath>
#include "Movement.h"

namespace Engine {

namespace Kinetic {

Movement::Movement(const Misc::Vector2d & from, const Misc::Vector2d & to, double accel, double speed, double max) {
	this->departure		= from;
	this->destination	= to;
	this->maxSpeed		= max;
	this->speed			= max;
	this->acceleration	= accel;
}

Movement::Movement() {
  maxSpeed = speed = acceleration = 0.0f;
}

Movement::~Movement() {
}

Misc::Vector2d Movement::update(int delta) {
  	if (speed < maxSpeed) speed += acceleration*delta/1000.0f;
  	departure.x += (destination.x - departure.x)*speed*delta/1000.f;
  	departure.y += (destination.y - departure.y)*speed*delta/1000.f;
	if ((std::abs(destination.x - departure.x) < 0.01f) && (std::abs(destination.y - departure.y) < 1.0f)) departure = destination;
	return departure;
}


} // namespace Engine::Kinetic

} // namespace Engine
